/**
 * @file   PA_F.cpp
 * @author ZL <zuoling@Black>
 * @date   Fri Oct  7 01:17:12 2022
 * 
 * @brief  1.8.2 PA_F
 * 
 * 
 */

#include "EquationSolver.h"
/** 
 * 
 * 
 * @param l 
 * @param h 
 * @param D 
 * @param b 
 * 
 * @return Create three function classes in Topic F
 */
class F : public Function
{
private:
    double A;
    double B;
    double C;
    double E;/// create const A,B,C,E.
public:
    F(double l, double h, double D, double b)
	{
	    A = l*sin(b/180*pi);
	    B = l*cos(b/180*pi);
	    C = (h+0.5*D)*sin(b/180*pi)-0.5*D*tan(b/180*pi);
	    E = (h+0.5*D)*cos(b/180*pi)-0.5*D;

	};
    /// Generate the corresponding A, B, C and D according to the input l, h, D and b.
    double operator ()(double a)
	{
	    double y;
	    y = A*sin(a/180*pi)*cos(a/180*pi)+B*sin(a/180*pi)*sin(a/180*pi)-C*cos(a/180*pi)-E*sin(a/180*pi);
	    return y;
	};
    double diff(double a)
	{
	    double y;
	    y = A*(cos(a/180*pi)*cos(a/180*pi)-sin(a/180*pi)*sin(a/180*pi))+2*B*sin(a/180*pi)*cos(a/180*pi)+C*sin(a/180*pi)-E*cos(a/180*pi);
	    return y;
	}
};

int main(int argc, char* argv[])
{
    F f1(89, 49, 55, 11.5);
    F f2(89, 49, 30, 11.5);
    F f3(89, 49, 55, 11.5);
    Newton n1(33, eps, 100, f1);
    Newton n2(33, eps, 100, f2);
    Secant s3(30, 35, eps, 100, f3);/// Initial values is close to alpha
    Secant s4(0, 90, eps, 100, f3);/// Initial values away from alpha
    double y1 = n1.solve();
    double y2 = n2.solve();
    double y3 = s3.solve();
    double y4 = s4.solve();
    
    std::cout << "(a) Newton method, alpha = " << y1 << std::endl;
    std::cout << "(b) Newton method, alpha = " << y2 << std::endl;
    std::cout << "(c) Secant method, alpha(30~35) = " << y3 << std::endl;
    std::cout << "    Secant method, alpha(0~90) = " << y4 << std::endl;
    return 0;
};
